#include <sys/un.h>
#include <time.h>
#include <sys/times.h>
#include <sys/sysinfo.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <net/route.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#include <syslog.h>
#include <netinet/in.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/socket.h>

#include "cms_event.h"
#include "cms_log.h"
#include "task_utils.h"
#include "task_module.h"
#include "task_common.h"
#include "cms_utils.h"


int getWanPhysicalType(char *wanPhysicalType){
	FILE *fp = NULL;
	char buf[32] = {0};
	char *tmp = NULL;
	char *Ptr=NULL;

	if((fp = fopen(WAN_DEVICE_FILE,"r")) == NULL){
		return -1;
	}

	if(fgets(buf,32,fp) != NULL){
		if((tmp = strtok_r(buf,"=",&Ptr)) != NULL){
			CMS_LOG(LL_INFO, "getWanPhysicalType--%s--\n",tmp);
			strncpy(wanPhysicalType, tmp, strlen(tmp));
			fclose(fp);
			return 1;
		}
	}

	fclose(fp);
	return -1;
}


int getWanPhysicalTypeAndIfname(char *wanPhysicalType, char *wanIfname){
	FILE *fp = NULL;
	char buf[32] = {0};
	char *tmp = NULL;
	char *Ptr=NULL;

	if((fp = fopen(WAN_DEVICE_FILE,"r")) == NULL){
		return -1;
	}

	if(fgets(buf,32,fp) != NULL){
		if((tmp = strtok_r(buf,"=",&Ptr)) != NULL){
			CMS_LOG(LL_INFO, "getWanPhysicalType--%s--\n",tmp);
			strncpy(wanPhysicalType, tmp, strlen(tmp));
			if((tmp = strtok_r(NULL,"=",&Ptr)) != NULL){
				CMS_LOG(LL_INFO, "getWanPhysicalType--%s--\n",tmp);
				strncpy(wanIfname, tmp, strlen(tmp));
				if(wanIfname[strlen(tmp)-1] == '\n')
					wanIfname[strlen(tmp)-1]=0;			
				fclose(fp);
				return 1;
			}
		}
	}

	fclose(fp);
	return -1;
}


